package com.soft.cake.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.soft.cake.pojo.Product;
import com.soft.cake.service.IProductService;

/**
 * @author RexALun
 * @description use to turn to thymeleaf element
 */
@Controller
public class IndexController {
	
	@Autowired
	private IProductService productService;
	
	/**
	 * @author Huo Sa
	 * @description 查询前八条记录用于首页展示
	 */
	@RequestMapping("/index")
	public String index(Model model, HttpServletResponse response) {
		List<Product> products = new ArrayList<Product>();
		products = productService.selectEightProducts();
		model.addAttribute("products", products);
		return "index";
	}

	/**
	 * @author Huo Sa
	 * @description 产品页面重定向去Index页面
	 */
	@RequestMapping("/product/index")
	public String redirecttoindex(Model model, HttpServletResponse response) {
		return "redirect:/index";
	}
	@RequestMapping("/test")
	public String test(Model model, HttpServletResponse response) {
		return "test";
	}
	
	@RequestMapping("/account")
	public String account(Model model, HttpServletResponse response) {
		return "account";
	}
	
	@RequestMapping("/checkout")
	public String checkout(Model model, HttpServletResponse response) {
		return "checkout";
	}
	
	@RequestMapping("/contact")
	public String contact(Model model, HttpServletResponse response) {
		return "contact";
	}
	
	@RequestMapping("/single")
	public String single(Model model, HttpServletResponse response) {
		return "single";
	}
	
	@RequestMapping("/products")
	public String products(Model model, HttpServletResponse response) {
		return "products";
	}
	
	@RequestMapping("/order")
	public String order(Model model, HttpServletResponse response) {
		return "order";
	}
	
	@RequestMapping("/orderinfo")
	public String orderinfo(Model model, HttpServletResponse response) {
		return "orderinfo";
	}
	
	@RequestMapping("/pay")
	public String pay(Model model, HttpServletResponse response) {
		return "pay";
	}
	
	@RequestMapping("/single/products")
	public String singleproducts(Model model, HttpServletResponse response) {
		return "products";
	}
	
	@RequestMapping("/single/account")
	public String singleaccount(Model model, HttpServletResponse response) {
		return "account";
	}
	
	@RequestMapping("/single/contact")
	public String singlecontact(Model model, HttpServletResponse response) {
		return "contact";
	}
	
	@RequestMapping("/single/order")
	public String singleorder(Model model, HttpServletResponse response) {
		return "order";
	}
}
